package com.itfallrain.service;

import com.itfallrain.common.MD5Encode;
import com.itfallrain.dao.UserMapper;
import com.itfallrain.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    public long getUserCount(){

        return userMapper.getUserCount();
    }
    public List<Map<String,Object>> getAll(int page, int limit){
        Map<String,Object> map=new HashMap();
        int start=(page-1)*limit;
        map.put("start",start);
        map.put("limit",limit);
        return userMapper.selectAll(map);
    }
//    新增用户
    public int selectAlls(User user){
        user.setPassword(MD5Encode.encode(user.getPassword()));
        return userMapper.insert(user);
    }
//    删除用户
    public int delectAlls(int id){
        return userMapper.deleteByPrimaryKey(id);
    }
//    修改用户信息
    public int updateAlls(User user){
        user.setPassword(MD5Encode.encode(user.getPassword()));
        return userMapper.updateByPrimaryKeySelective(user);
    }
}
